using UnityEngine;
using System.Collections;

public class EventAttributeChange : MonoBehaviour {

	GUIButton button;
	public ATTRIBUTES attribute;
	public bool raiseValue;
	public GameObject decreaseButton;
	
	void Start ()
	{
		button = gameObject.GetComponent<GUIButton>();
		button.OnClickCallback += OnClick;
		if (AttributesController.GetInstance().GetActiveAttributeSet() == null)
			return;
		CheckActivation();
	}	
	void OnClick(Vector3 pos){
		if (!button.enabled)
			return;
		if (raiseValue){
			AttributesController.GetInstance().GetActiveAttributeSet().
			BuyAttributePoint(attribute, true);
			
			if(AttributesController.GetInstance().GetActiveAttributeSet()
			.GetAttributeTotalValue(attribute) > 1 && raiseValue)
				this.decreaseButton.SetActive(true);
				
		}else{
			AttributesController.GetInstance().GetActiveAttributeSet().
			BuyAttributePoint(attribute, false);
			
			if(AttributesController.GetInstance().GetActiveAttributeSet()
			.GetAttributeTotalValue(attribute) == 1 && !raiseValue)
				this.gameObject.SetActive(false);
		}
	}
	public void CheckActivation(){
		if(AttributesController.GetInstance().GetActiveAttributeSet()
		.GetAttributeTotalValue(attribute) == 1 && !raiseValue)
			this.gameObject.SetActive(false);	
		else
			this.gameObject.SetActive(true);	
	}
}
